package com.zuul.gateway.config;

import com.zuul.gateway.entity.CommonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * create by yongli on 2021-10-08 17:29
 * <p>
 * 这个不需要交给spring托管吗
 */
@Component
public class BaseExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(BaseExceptionHandler.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CommonResult handleException() {
        logger.info("对于内部错误的拦截");
        return new CommonResult("系统内部错误");
    }


    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public CommonResult handleException404() {
        logger.info("对于内部错误的拦截");
        return new CommonResult("系统内部错误");
    }
}
